/**
 * 采购对比contrastList.js
 * 版本号： v1.0.0
 */
$(function(){
    var purId = $('#purId_').val();
    $("#contrast_dataList").datagrid({
        fitColumns: true,
        fit:true,
        method: "POST",
        rownumbers: true,
        singleSelect:true,
        pagination: true,
        striped: true,
        border: false,
        pageSize:20,
        pageList:[20,50,100],
        url: CONTEXT_PATH + '/purchaseApplyCheck/getContrastList.do?purId='+purId,
        idField: 'purId',
        columns: [
            [
                {field: 'checkState', title: '审核状态', width: 50, fixed: true,hidden:true},
                {field: 'materialName', title: '材料名称', width: 140, fixed: true},
                {field: 'standardType', title: '规格型号', width: 140, fixed: true},
                {field: 'totalCount', title: '合同量', width: 100, fixed: true,align:'center'},
                {field: 'purchasedNum', title: '已请购量', width: 100, fixed: true,align:'center'},
                {field: 'leftCount', title: '合同剩余量', width: 100, fixed: true,align:'center'},
                {field: 'purdNum', title: '本次请购量', width: 100, fixed: true,align:'center'},
                {field: 'meteringUnit', title: '计量单位', width: 70, fixed: true,align:'center'},
                {field: 'contrast_result', title: '比对结果', width: 120,align:'center',formatter:function(val,row){
                        var flag = 0;
                        var checkState = row.checkState;
                        var purdNum = row.purdNum;
                        var leftCount = row.leftCount;
                        var purchasedNum = row.purchasedNum;
                        //如果申请已通过，则减去本次请购量，再对比结果
                        if(checkState == 2){
                            if(leftCount >= purchasedNum - purdNum){
                                flag = 1;
                            }else{
                                flag = -1;
                            }
                        }else{
                            if(leftCount >= purdNum){
                                flag = 1;
                            }else{
                                flag = -1;
                            }
                        }
                        if(purdNum == 0){
                            return '<span style="background-color: #43e496;height:80%">本次未请购</span>';
                        }
                        if(flag < 0){
                            return '<span style="background-color: #D43030">已超</span>';
                        }
                        if(flag > 0){
                            return '<span style="background-color: #2A82E4;height: 80%">满足</span>';
                        }
                }}
            ]
        ]
    });
});